home *** CD-ROM | disk | FTP | other *** search
/ Champak 109 / Vol 109.iso / games / bubble_t.swf / scripts / frame_1 / DoAction.as < prev   
Text File  |  2008-11-12  |  28KB  |  1,175 lines

  1. function init()
  2. {
  3.    gDebug = false;
  4.    gSticky = {val:1};
  5.    gMoveGun = {val:0};
  6.    gAutomatic = {val:0};
  7.    gRandomLevels = {val:0};
  8.    gUseKeyboard = {val:1};
  9.    gHighScoreEligible = {val:1};
  10.    gOption = [gSticky,gMoveGun,gAutomatic,gRandomLevels,gUseKeyboard,gHighScoreEligible];
  11.    gDefaultOption = [gSticky.val,gMoveGun.val,gAutomatic.val,gRandomLevels.val,gUseKeyboard.val,gHighScoreEligible.val];
  12.    var i = 0;
  13.    while(i < gOption.length)
  14.    {
  15.       _root["option_" + i].gotoAndStop(gOption[i].val + 1);
  16.       _root["option_" + i].pID = i;
  17.       gOption[i].pID = i;
  18.       i++;
  19.    }
  20.    gGunDir = 1;
  21.    gGunSpeed = 25;
  22.    gBombFrame = 6;
  23.    gBombRadius = 2;
  24.    gLevel = 1;
  25.    score = 0;
  26.    scorecheck = "0";
  27.    cNORMAL = 1;
  28.    cFIRE = 2;
  29.    cCONTACT = 3;
  30.    cREMOVE = 4;
  31.    cDEBUG = 5;
  32.    cCEILING = 6;
  33.    cSTART = 7;
  34.    cMOVE = 8;
  35.    cFINISH = 9;
  36.    cSTARTGAME = 10;
  37.    cSTARTLEVEL = 11;
  38.    gMode = cSTARTGAME;
  39.    gLevelData = new Array();
  40.    gLevelData.push(" ");
  41.    gLevelData.push("112233D332211.3311224221133");
  42.    gLevelData.push("1122322322111.40233F3320444.1100100100111");
  43.    gLevelData.push("I11444E11444I.2233223322332.1144411144411");
  44.    gLevelData.push("0023344433200.002K0440K2000.0020004000200.0124000042100.0114400044110");
  45.    gLevelData.push("3D212434212D2.3420243420242.4341014341014.1300001300001.00100000M0000");
  46.    gLevelData.push("4221322432213.4214324232143.4001300430013.000D000A000D0.0002200220022");
  47.    gLevelData.push("01101E0E10110.0300300300300.02B0440220D40.0300300300300.0110110110110.0300300300300.0440220440220");
  48.    gLevelData.push("104330O033401.1043033034010.01040E2E04010.0104000040100.0030000000300.0300000000300.0300000000030");
  49.    gLevelData.push("02244C44C4422.2421014101242.0B2100220012B.030000J000030.0220000000022.4340000000434");
  50.    gLevelData.push("1O201020102O1.1023A020A3201.1020132310201.1020102010201.4324332443243.03400DC003400");
  51.    gLevelData.push("1123201102321.12K201A102O21.0002300003200.0004310134000.0003400004300.0034000004300.0000300003000.0000C000C0000");
  52.    gLevelData.push("0120430210340.F01304M0240G0.0300400200100.3304402201100.010A20D30B400.0010040020000.0001003002000");
  53.    gLevelData.push("0040J3443J040.D40223432204D.0340030030043.301101A101103.0000030030000");
  54.    gLevelData.push("22A03322330A2.010211P112010.0102034430201.2000340430002.0231010010132.0F100000001F0.0010000000010");
  55.    gLevelData.push("0131141411310.010H0110H0100.02FC42224CF20.0030033003000.0302214122030.0310100101300");
  56.    gLevelData.push("00422H3H23322.040404040L040.0A14001A04040.010A10101A011.03C0104D01001.0003C0004D033");
  57.    gLevelData.push("3K323K323K323.2112112112112.4343434343434.0400040040004.00D000404000D.0400040040004");
  58.    gLevelData.push("2300340013004.4G111H222G111.0032004100340.E123G312F2411.0420021001400.0400020001000.0040002000100");
  59.    gLevelData.push("033130301M031.A13L11334313G.0341034113141.031331C303031.0302001030113.0202020200202.02000B00B0200");
  60.    gLevelData.push("1I1443G3221I1.114H4332F2110.2323121434324.1414343212131");
  61.    if(gDebug)
  62.    {
  63.       gLevelData = [" "];
  64.       gLevelData.push("112233D332211.3311224221133");
  65.    }
  66.    gSpacing = 20;
  67.    gRdX = (- gSpacing) / 2;
  68.    gRdY = gSpacing * 1.7320508075688774 / 2;
  69.    gCdX = gSpacing;
  70.    gCdY = 0;
  71.    gGunLength = 53;
  72.    gProjectileSpeed = 300;
  73.    gDieDuration = 0;
  74.    gNumTypes = 4;
  75.    gNumRecentTypes = 3;
  76.    gFrameTimer = -1;
  77.    gMaxSquash = 0.4;
  78.    gMinSpacing = gSpacing * (1 - gMaxSquash) / 2;
  79.    gFireSound = new Sound();
  80.    gBounceSound = new Sound();
  81.    gAttachSound = new Sound();
  82.    gBonusSound = new Sound();
  83.    gPopSound = new Sound();
  84.    gLostBubbleSound = new Sound();
  85.    gNextLevelSound = new Sound();
  86.    gGameOverSound = new Sound();
  87.    gCeilingSound = new Sound();
  88.    gIntroSound = new Sound(_root.intro_sound_MC);
  89.    gIntroSound.attachSound("intro_sound");
  90.    gIntroSound.start(0,30000);
  91.    gNewBubbleSpeedDefault = 350;
  92.    gNewBubbleSpeedSlow = 150;
  93.    gPopping = 0;
  94. }
  95. function skipLevelKeyUp(vObj)
  96. {
  97.    var val = Number(vObj.input);
  98.    if(isNaN(val))
  99.    {
  100.       vObj.input = "";
  101.    }
  102.    else if(val < 1)
  103.    {
  104.       vObj.input = "";
  105.    }
  106.    else
  107.    {
  108.       vObj.input = Math.floor(val);
  109.       if(allowFixedLevels())
  110.       {
  111.          gRandomLevels.val = 0;
  112.          _root["option_" + gRandomLevels.pID].gotoAndStop(1);
  113.       }
  114.       else
  115.       {
  116.          gRandomLevels.val = 1;
  117.          _root["option_" + gRandomLevels.pID].gotoAndStop(2);
  118.       }
  119.    }
  120.    checkEligible();
  121. }
  122. function allowFixedLevels()
  123. {
  124.    var lVal = _root.choose_level_MC.input;
  125.    if(lVal == "" || isNaN(Number(lVal)))
  126.    {
  127.       lVal = 1;
  128.    }
  129.    var lLevel = Number(lVal);
  130.    if(lLevel >= gLevelData.length)
  131.    {
  132.       return false;
  133.    }
  134.    return true;
  135. }
  136. function pressedRadioButton(vObj)
  137. {
  138.    if(gOption[vObj.pID] == gHighScoreEligible && gOption[vObj.pID].val == 1)
  139.    {
  140.       return undefined;
  141.    }
  142.    var lCurrentSelection = gOption[vObj.pID].val + 1;
  143.    vObj.gotoAndStop(3 - lCurrentSelection);
  144. }
  145. function draggedOut(vObj)
  146. {
  147.    if(gOption[vObj.pID] == gHighScoreEligible && gOption[vObj.pID].val == 1)
  148.    {
  149.       return undefined;
  150.    }
  151.    var lCurrentSelection = gOption[vObj.pID].val + 1;
  152.    vObj.gotoAndStop(lCurrentSelection);
  153. }
  154. function draggedOver(vObj)
  155. {
  156.    if(gOption[vObj.pID] == gHighScoreEligible && gOption[vObj.pID].val == 1)
  157.    {
  158.       return undefined;
  159.    }
  160.    var lCurrentSelection = gOption[vObj.pID].val + 1;
  161.    vObj.gotoAndStop(3 - lCurrentSelection);
  162. }
  163. function releasedRadioButton(vObj)
  164. {
  165.    gOption[vObj.pID].val = 1 - gOption[vObj.pID].val;
  166.    vObj.gotoAndStop(gOption[vObj.pID].val + 1);
  167.    if(gOption[vObj.pID] == gHighScoreEligible)
  168.    {
  169.       if(gHighScoreEligible.val == 1)
  170.       {
  171.          var i = 0;
  172.          while(i < gOption.length)
  173.          {
  174.             if(gOption[i] != gHighScoreEligible)
  175.             {
  176.                gOption[i].val = gDefaultOption[i];
  177.                _root["option_" + i].gotoAndStop(gDefaultOption[i] + 1);
  178.             }
  179.             i++;
  180.          }
  181.          _root.choose_level_MC.input = "";
  182.       }
  183.       else
  184.       {
  185.          gOption[vObj.pID].val = 1 - gOption[vObj.pID].val;
  186.          vObj.gotoAndStop(gOption[vObj.pID].val + 1);
  187.       }
  188.    }
  189.    else
  190.    {
  191.       if(gOption[vObj.pID] == gRandomLevels)
  192.       {
  193.          var lFixedOK = allowFixedLevels();
  194.          if(!lFixedOK && !gRandomLevels.val)
  195.          {
  196.             gRandomLevels.val = 1;
  197.             vObj.gotoAndStop(2);
  198.          }
  199.       }
  200.       checkEligible();
  201.    }
  202. }
  203. function checkEligible()
  204. {
  205.    var ok = 1;
  206.    var i = 0;
  207.    while(i < gOption.length)
  208.    {
  209.       if(gOption[i] != gHighScoreEligible)
  210.       {
  211.          if(gOption[i].val != gDefaultOption[i])
  212.          {
  213.             ok = 0;
  214.          }
  215.       }
  216.       i++;
  217.    }
  218.    if(1 < Number(_root.choose_level_MC.input))
  219.    {
  220.       ok = 0;
  221.    }
  222.    gHighScoreEligible.val = ok;
  223.    _root["option_" + gHighScoreEligible.pID].gotoAndStop(ok + 1);
  224. }
  225. function beginLevel()
  226. {
  227.    gNextLevelSound.attachSound("next_level_sound");
  228.    gNextLevelSound.start();
  229. }
  230. function startGame()
  231. {
  232.    var lLevel = Number(_root.choose_level_MC.input);
  233.    if(!isNaN(lLevel) && lLevel >= 1)
  234.    {
  235.       gLevel = Math.floor(lLevel);
  236.    }
  237.    gotoAndStop(3);
  238. }
  239. function levelBubbleDone()
  240. {
  241.    gMode = cNORMAL;
  242.    _root.level_bubble.gotoAndStop(1);
  243.    _root.level_bubble.bubble.gotoAndStop("showtext");
  244.    _root.level_bubble.bubble.bubble.graphic.gotoAndStop(1);
  245.    gotoAndStop(6);
  246. }
  247. function popLevelBubble()
  248. {
  249.    _root.level_bubble.bubble.bubble.graphic.gotoAndPlay("pop");
  250.    _root.level_bubble.bubble.gotoAndStop("hidetext");
  251.    gPopSound.attachSound("pop_sound");
  252.    gPopSound.start();
  253. }
  254. function setUp()
  255. {
  256.    gIntroSound.stop();
  257.    if(gMode == cSTARTGAME)
  258.    {
  259.       gNewBubbleStartX = _root.new_bubble._x;
  260.       gNewBubbleStartY = _root.new_bubble._y;
  261.       gStartingOrigin = {x:_root.bubble_MCA._x,y:_root.bubble_MCA._y};
  262.       if(!gRandomLevels.val)
  263.       {
  264.          gNumLevels = gLevelData.length;
  265.       }
  266.       else
  267.       {
  268.          gNumLevels = 0;
  269.       }
  270.    }
  271.    if(!gRandomLevels.val)
  272.    {
  273.       gData = gLevelData[gLevel].split(".");
  274.    }
  275.    _root.level_bubble.bubble.level_display = "Level\r" + gLevel;
  276.    var lLevelColor = 1 + (gLevel - 1) % 4;
  277.    _root.level_bubble.bubble.bubble.gotoAndStop(lLevelColor);
  278.    gMode = cSTARTLEVEL;
  279.    _root.controls.gotoAndStop(gUseKeyboard.val + 1);
  280.    _root.warning_message.gotoAndStop(gHighScoreEligible.val + 1);
  281.    _root.score_display = scorecheck;
  282.    Mouse.hide();
  283.    if(gDebug)
  284.    {
  285.       Mouse.show();
  286.    }
  287.    _root.level_display = gLevel;
  288.    gOrigin = {x:gStartingOrigin.x,y:gStartingOrigin.y};
  289.    _root.bubble_MCA._x = gOrigin.x;
  290.    _root.bubble_MCA._y = gOrigin.y;
  291.    _root.ceiling._y = _root.bubble_MCA._y - gSpacing / 2;
  292.    _root.frame_shadow.gotoAndStop("hide");
  293.    gCeilingRow = 0;
  294.    gCeilingY = 0;
  295.    if(gAutomatic.val)
  296.    {
  297.       gNewBubbleSpeed = gNewBubbleSpeedSlow;
  298.    }
  299.    else
  300.    {
  301.       gNewBubbleSpeed = gNewBubbleSpeedDefault;
  302.    }
  303.    if(gLevel < 6)
  304.    {
  305.       gCeilingDelay = 25000 * Math.pow(0.95,gLevel - 1);
  306.    }
  307.    else if(gLevel < 11)
  308.    {
  309.       gCeilingDelay = 25000 * Math.pow(0.95,gLevel + 5);
  310.    }
  311.    else if(gLevel < 16)
  312.    {
  313.       gCeilingDelay = 25000 * Math.pow(0.95,gLevel + 7);
  314.    }
  315.    else
  316.    {
  317.       gCeilingDelay = 25000 * Math.pow(0.95,gLevel + 8);
  318.    }
  319.    if(gDebug)
  320.    {
  321.       gCeilingDelay = 9000000;
  322.    }
  323.    if(gLevel < 13)
  324.    {
  325.       var lBonusFreq = 2 + Math.floor((gLevel - 1) / 3);
  326.    }
  327.    else if(gLevel < 20)
  328.    {
  329.       var lBonusFreq = 6;
  330.    }
  331.    else
  332.    {
  333.       var lBonusFreq = 7;
  334.    }
  335.    gHaveBonus = new Array();
  336.    var i = 0;
  337.    while(i < 10)
  338.    {
  339.       if(i < lBonusFreq)
  340.       {
  341.          gHaveBonus.push(1);
  342.       }
  343.       else
  344.       {
  345.          gHaveBonus.push(0);
  346.       }
  347.       i++;
  348.    }
  349.    gWhichBonus = new Array();
  350.    if(gLevel < 5)
  351.    {
  352.       gWhichBonus = [2,2,3,3];
  353.    }
  354.    else if(gLevel < 9)
  355.    {
  356.       gWhichBonus = [2,2,3,3,4];
  357.    }
  358.    else if(gLevel < 13)
  359.    {
  360.       gWhichBonus = [2,3,3,4,4,5];
  361.    }
  362.    else if(glevel < 17)
  363.    {
  364.       gWhichBonus = [2,3,4,4,5,5];
  365.    }
  366.    else if(glevel < 21)
  367.    {
  368.       gWhichBonus = [3,4,4,5,5];
  369.    }
  370.    else if(gLevel < 25)
  371.    {
  372.       gWhichBonus = [3,4,5,5];
  373.    }
  374.    else if(gLevel < 29)
  375.    {
  376.       gWhichBonus = [3,4,5,5,5];
  377.    }
  378.    else
  379.    {
  380.       gWhichBonus = [4,5,5,5];
  381.    }
  382.    gHaveBonusSource = gHaveBonus.slice(0);
  383.    gWhichBonusSource = gWhichBonus.slice(0);
  384.    gCeilingTimer = getTimer();
  385.    gGunTimer = getTimer();
  386.    gBubbleLevel = 1;
  387.    gBubbleList = new Array();
  388.    gBubbleRow = new Array();
  389.    gBubbleCount = [0,0,0,0,0];
  390.    gBubble = new Array();
  391.    gNumRows = 30;
  392.    gRowLength = 13;
  393.    if(gRandomLevels.val)
  394.    {
  395.       gStartRows = 3;
  396.    }
  397.    else
  398.    {
  399.       gStartRows = gData.length;
  400.    }
  401.    var lInitialBonus = [1,1,2,2,3,3,4,4];
  402.    gNumCols = gRowLength + gNumRows;
  403.    var i = 0;
  404.    while(i < gNumRows)
  405.    {
  406.       gBubble[i] = new Array();
  407.       gBubbleRow[i] = new Array();
  408.       if(i < gStartRows)
  409.       {
  410.          var lStartCol = Math.ceil(i / 2);
  411.          var lEndCol = lStartCol + gRowLength - 1;
  412.          var lDataCol = 0;
  413.          var j = lStartCol;
  414.          while(lEndCol >= j)
  415.          {
  416.             if(gRandomLevels.val)
  417.             {
  418.                if(lInitialBonus.length == 0)
  419.                {
  420.                   trace("no bonuses left");
  421.                   var lBonus = 1;
  422.                   var lType = Math.ceil(Math.random() * 4);
  423.                }
  424.                else
  425.                {
  426.                   trace("bonuses remain");
  427.                   var lBonus = randomBonus(0.2);
  428.                   if(lBonus == 1)
  429.                   {
  430.                      var lType = Math.ceil(Math.random() * 4);
  431.                   }
  432.                   else
  433.                   {
  434.                      var lIndex = Math.floor(Math.random() * lInitialBonus.length);
  435.                      var lType = lInitialBonus[lIndex];
  436.                      lInitialBonus.splice(lIndex,1);
  437.                   }
  438.                }
  439.             }
  440.             else
  441.             {
  442.                var lCode = gData[i].charAt(lDataCol);
  443.                var lType = Number(lCode);
  444.                var lBonus = 1;
  445.                if(isNaN(lType))
  446.                {
  447.                   var lNum = lCode.charCodeAt(0);
  448.                   lType = (lNum - 65) % 4 + 1;
  449.                   var lBonus = Math.floor((lNum - 65) / 4) + 2;
  450.                }
  451.             }
  452.             if(lType)
  453.             {
  454.                var lName = "bubble_" + i + "_" + j;
  455.                _root.bubble_MCA.attachMovie("bubble",lName,gBubbleLevel++);
  456.                var b = _root.bubble_MCA[lName];
  457.                b.pRow = i;
  458.                b.pCol = j;
  459.                if(gDebug)
  460.                {
  461.                   b.bubble.position_display = "" + i + "," + j;
  462.                }
  463.                placeBubble(b);
  464.                b.bubble.gotoAndStop(lType);
  465.                b.bubble.graphic.bonus.gotoAndStop(lBonus);
  466.                gBubble[i][j] = b;
  467.                gBubbleList.push(b);
  468.                gBubbleRow[i].push(b);
  469.                gBubbleCount[lType]++;
  470.             }
  471.             lDataCol++;
  472.             j++;
  473.          }
  474.       }
  475.       i++;
  476.    }
  477.    gTopLevel = 1000;
  478.    gFutureType = Math.ceil(Math.random() * gNumTypes);
  479.    gFutureBonus = 1;
  480.    gNextType = Math.ceil(Math.random() * gNumTypes);
  481.    gNextBonus = 1;
  482.    gCurrentType = Math.ceil(Math.random() * gNumTypes);
  483.    gCurrentBonus = 1;
  484.    _root.projectile._x = _root.gun._x;
  485.    _root.projectile._y = _root.gun._y;
  486.    _root.new_bubble._x = gNewBubbleStartX;
  487.    _root.new_bubble._y = gNewBubbleStartY;
  488.    gNewBubbleMode = cSTART;
  489.    _root.future_bubble.gotoAndStop(1);
  490.    if(gDebug)
  491.    {
  492.       gNextType = 4;
  493.       gCurrentType = 4;
  494.    }
  495.    _root.projectile.bubble.gotoAndStop(gCurrentType);
  496.    _root.projectile.bubble.graphic.bonus.gotoAndStop(gCurrentBonus);
  497.    _root.new_bubble.bubble.gotoAndStop(gNextType);
  498.    _root.new_bubble.bubble.graphic.bonus.gotoAndStop(gNextBonus);
  499.    _root.future_bubble.bubble.gotoAndStop(gFutureType);
  500.    _root.future_bubble.bubble.graphic.bonus.gotoAndStop(gFutureBonus);
  501.    gRecentType = [gCurrentType,gNextType,gFutureType];
  502. }
  503. function randomType()
  504. {
  505.    var lTypeChoice = new Array();
  506.    var k = 1;
  507.    while(gNumTypes >= k)
  508.    {
  509.       if(0 < gBubbleCount[k])
  510.       {
  511.          lTypeChoice.push(k);
  512.       }
  513.       k++;
  514.    }
  515.    if(lTypeChoice.length < 2)
  516.    {
  517.       return lTypeChoice[0];
  518.    }
  519.    var lCount = [0,0,0,0,0];
  520.    var i = 0;
  521.    while(i < gRecentType.length)
  522.    {
  523.       lCount[gRecentType[i]]++;
  524.       i++;
  525.    }
  526.    var lProb = new Array();
  527.    var lTotal = 0;
  528.    var i = 1;
  529.    while(4 >= i)
  530.    {
  531.       lProb[i] = gRecentType.length - lCount[i];
  532.       if(getOne(lTypeChoice,i) == -1)
  533.       {
  534.          lProb[i] = 0;
  535.       }
  536.       lTotal += lProb[i];
  537.       i++;
  538.    }
  539.    var i = 1;
  540.    while(4 >= i)
  541.    {
  542.       lProb[i] /= lTotal;
  543.       i++;
  544.    }
  545.    var n = Math.random();
  546.    var p = 0;
  547.    var i = 1;
  548.    while(4 >= i)
  549.    {
  550.       p += lProb[i];
  551.       if(n < p)
  552.       {
  553.          gRecentType.push(i);
  554.          if(gNumRecentTypes < gRecentType.length)
  555.          {
  556.             gRecentType.shift();
  557.          }
  558.          return i;
  559.       }
  560.       i++;
  561.    }
  562.    var lIndex = Math.floor(Math.random() * lTypeChoice.length);
  563.    gRecentType.push(lTypeChoice[lIndex]);
  564.    if(gNumRecentTypes < gRecentType.length)
  565.    {
  566.       gRecentType.shift();
  567.    }
  568.    return lTypeChoice[lIndex];
  569. }
  570. function randomBonus(vProb)
  571. {
  572.    if(Math.random() >= vProb)
  573.    {
  574.       var lBonus = 0;
  575.    }
  576.    else
  577.    {
  578.       var lBonus = 1;
  579.    }
  580.    if(lBonus)
  581.    {
  582.       lBonus = Math.ceil(Math.random() * 4 + 1);
  583.    }
  584.    else
  585.    {
  586.       lBonus = 1;
  587.    }
  588.    return lBonus;
  589. }
  590. function chooseBonus()
  591. {
  592.    if(gHaveBonusSource.length == 0)
  593.    {
  594.       gHaveBonusSource = gHaveBonus.slice(0);
  595.    }
  596.    var i = Math.floor(Math.random() * gHaveBonusSource.length);
  597.    var h = gHaveBonusSource[i];
  598.    gHaveBonusSource.splice(i,1);
  599.    if(h == 0)
  600.    {
  601.       return 1;
  602.    }
  603.    if(gWhichBonusSource.length == 0)
  604.    {
  605.       gWhichBonusSource = gWhichBonus.slice(0);
  606.    }
  607.    var i = Math.floor(Math.random() * gWhichBonusSource.length);
  608.    var b = gWhichBonusSource[i];
  609.    gWhichBonusSource.splice(i,1);
  610.    return b;
  611. }
  612. function onStage(r, c)
  613. {
  614.    var lLoc = gridToPixels(r,c);
  615.    if(lLoc.x < _root.wall_left._x + gSpacing / 2)
  616.    {
  617.       return false;
  618.    }
  619.    if(_root.wall_right._x - gSpacing / 2 < lLoc.x)
  620.    {
  621.       return false;
  622.    }
  623.    if(lLoc.y < _root.wall_top._y + gSpacing / 2)
  624.    {
  625.       return false;
  626.    }
  627.    return true;
  628. }
  629. function placeBubble(vBubble)
  630. {
  631.    vBubble._x = vBubble.pRow * gRdX + vBubble.pCol * gCdX;
  632.    vBubble._y = vBubble.pRow * gRdY + vBubble.pCol * gCdY;
  633. }
  634. function gridToPixels(r, c)
  635. {
  636.    var x0 = r * gRdX + c * gCdX + _root.bubble_MCA._x;
  637.    var y0 = r * gRdY + c * gCdY + _root.bubble_MCA._y;
  638.    return {x:x0,y:y0};
  639. }
  640. function checkKeyboard(vTime)
  641. {
  642.    var lTurning = false;
  643.    if(gUseKeyboard.val)
  644.    {
  645.       if(Key.isDown(37))
  646.       {
  647.          if(Key.isDown(Key.SHIFT))
  648.          {
  649.             turnGun(-1);
  650.          }
  651.          else
  652.          {
  653.             turnGunTimed(-5,vTime);
  654.             lTurning = true;
  655.             gGunTimer = vTime;
  656.          }
  657.       }
  658.       if(Key.isDown(39))
  659.       {
  660.          if(Key.isDown(Key.SHIFT))
  661.          {
  662.             turnGun(1);
  663.          }
  664.          else
  665.          {
  666.             turnGunTimed(5,vTime);
  667.             lTurning = true;
  668.             gGunTimer = vTime;
  669.          }
  670.       }
  671.    }
  672.    if(!lTurning)
  673.    {
  674.       gGunTimer = 0;
  675.    }
  676.    if(gMode != cNORMAL)
  677.    {
  678.       return undefined;
  679.    }
  680.    if(gUseKeyboard.val && Key.isDown(32) || gAutomatic.val)
  681.    {
  682.       fireProjectile();
  683.    }
  684. }
  685. function turnGunTimed(vAngle, vTime)
  686. {
  687.    if(gGunTimer)
  688.    {
  689.       vAngle *= (vTime - gGunTimer) / 62;
  690.    }
  691.    vAngle *= 0.017453292519943295;
  692.    if(20 < vAngle)
  693.    {
  694.       vAngle = 20;
  695.    }
  696.    else if(vAngle < -20)
  697.    {
  698.       vAngle = -20;
  699.    }
  700.    var a = (_root.gun.barrel._rotation - 90) * 3.141592653589793 / 180;
  701.    a += vAngle;
  702.    if(-0.1 < a)
  703.    {
  704.       a = -0.1;
  705.    }
  706.    if(a < -3.041592653589793)
  707.    {
  708.       a = -3.041592653589793;
  709.    }
  710.    _root.gun.barrel._rotation = 90 + a * 180 / 3.141592653589793;
  711.    _root.angle_display = a;
  712.    _root.gun.barrel.pAngle = a;
  713.    _root.gun.barrel.pOldAngle = a;
  714. }
  715. function turnGun(vAngle)
  716. {
  717.    vAngle *= 0.017453292519943295;
  718.    var a = (_root.gun.barrel._rotation - 90) * 3.141592653589793 / 180;
  719.    a += vAngle;
  720.    if(-0.1 < a)
  721.    {
  722.       a = -0.1;
  723.    }
  724.    if(a < -3.041592653589793)
  725.    {
  726.       a = -3.041592653589793;
  727.    }
  728.    _root.gun.barrel._rotation = 90 + a * 180 / 3.141592653589793;
  729.    _root.angle_display = a;
  730.    _root.gun.barrel.pAngle = a;
  731.    _root.gun.barrel.pOldAngle = a;
  732. }
  733. function newBubbleDone()
  734. {
  735.    _root.new_bubble._x = _root.gun._x;
  736.    _root.new_bubble._y = _root.gun._y;
  737.    gNewBubbleMode = cFINISH;
  738.    if(gProjectileWaiting)
  739.    {
  740.       _root.projectile._x = _root.gun._x;
  741.       _root.projectile._y = _root.gun._y;
  742.       gProjectileWaiting = false;
  743.    }
  744. }
  745. function frameLoop()
  746. {
  747.    if(gFrameTimer == -1)
  748.    {
  749.       gFrameTimer = getTimer();
  750.       gCeilingTimer = getTimer();
  751.    }
  752.    var lTime = getTimer();
  753.    checkKeyboard(lTime);
  754.    if(gMode == cSTARTGAME || gMode == cSTARTLEVEL)
  755.    {
  756.       return undefined;
  757.    }
  758.    moveGun(lTime);
  759.    moveNewBubble(lTime);
  760.    if(gMode == cFIRE || gMode == cCONTACT || gMode == cREMOVE)
  761.    {
  762.       moveProjectile(lTime);
  763.    }
  764.    else if(gMode == cCEILING)
  765.    {
  766.       updateCeiling(lTime);
  767.    }
  768.    else if(gMode == cNORMAL)
  769.    {
  770.       checkCeiling(lTime);
  771.    }
  772.    else if(gMode == cDIE)
  773.    {
  774.       var n = gBubbleList.length;
  775.       if(n == 0 && lTime >= gDieTimer + gDieDuration)
  776.       {
  777.          _root.gun.barrel._rotation = 0;
  778.          if(gHighScoreEligible.val)
  779.          {
  780.             _root.submit_score_MC.gotoAndStop("show");
  781.          }
  782.          else
  783.          {
  784.             _root.submit_score_MC.gotoAndStop("hide");
  785.          }
  786.          Mouse.show();
  787.          gotoAndStop(11);
  788.       }
  789.       else if(0 < n)
  790.       {
  791.          var b = gBubbleList.pop();
  792.          b.bubble.graphic.bonus.gotoAndStop(1);
  793.          b.bubble.graphic.gotoAndPlay("pop");
  794.          gPopSound.attachSound("pop_sound");
  795.          gPopSound.start();
  796.       }
  797.    }
  798.    gFrameTimer = lTime;
  799. }
  800. function moveGun(vTime)
  801. {
  802.    if(!gMoveGun.val)
  803.    {
  804.       return undefined;
  805.    }
  806.    if(gMode != cNORMAL && gMode != cFIRE)
  807.    {
  808.       return undefined;
  809.    }
  810.    var x = _root.gun._x;
  811.    var w = 2 * gGunLength;
  812.    x += gGunDir * (vTime - gFrameTimer) * gGunSpeed / 1000;
  813.    if(x >= _root.wall_right._x - w / 2)
  814.    {
  815.       x = _root.wall_right._x - w / 2;
  816.       gGunDir *= -1;
  817.    }
  818.    else if(_root.wall_left._x + w / 2 >= x)
  819.    {
  820.       x = _root.wall_left._x + w / 2;
  821.       gGunDir *= -1;
  822.    }
  823.    if(_root.new_bubble._x == _root.gun._x)
  824.    {
  825.       _root.new_bubble._x = x;
  826.    }
  827.    _root.gun._x = x;
  828.    _root.tubing_main._xscale = (_root.gun._x - _root.tubing_1._x - 20) * 100 / 165;
  829.    if(_root.projectile._y == _root.gun._y)
  830.    {
  831.       _root.projectile._x = _root.gun._x;
  832.    }
  833. }
  834. function moveNewBubble(vTime)
  835. {
  836.    if(gNewBubbleMode != cMOVE)
  837.    {
  838.       return undefined;
  839.    }
  840.    var lDist = (vTime - gFrameTimer) * gNewBubbleSpeed / 1000;
  841.    var x = _root.new_bubble._x;
  842.    var y = _root.new_bubble._y;
  843.    if(y < _root.tubing_main._y && x == _root.tubing_1._x)
  844.    {
  845.       y += lDist;
  846.       if(y >= _root.tubing_main._y)
  847.       {
  848.          y = _root.tubing_main._y;
  849.       }
  850.    }
  851.    else if(y == _root.tubing_main._y && x != _root.gun._x)
  852.    {
  853.       x += lDist;
  854.       if(x >= _root.gun._x)
  855.       {
  856.          x = _root.gun._x;
  857.       }
  858.    }
  859.    else
  860.    {
  861.       y -= lDist;
  862.       if(_root.gun._y >= y)
  863.       {
  864.          y = _root.gun._y;
  865.          gNewBubbleMode = cFINISH;
  866.          newBubbleDone();
  867.       }
  868.    }
  869.    _root.new_bubble._x = x;
  870.    _root.new_bubble._y = y;
  871. }
  872. function updateCeiling(vTime)
  873. {
  874.    _root.frame_shadow.gotoAndStop("show");
  875.    var y = _root.ceiling._y;
  876.    y += 3;
  877.    var lDestY = _root.wall_top._y + gCeilingY;
  878.    if(y >= lDestY)
  879.    {
  880.       y = lDestY;
  881.       gOrigin = {x:_root.bubble_MCA._x,y:_root.bubble_MCA._y};
  882.       gMode = cNORMAL;
  883.    }
  884.    _root.ceiling._y = y;
  885.    _root.bubble_MCA._y = y + gSpacing / 2;
  886.    if(gMode == cNORMAL)
  887.    {
  888.       checkDie();
  889.    }
  890. }
  891. function checkDie()
  892. {
  893.    if(gCeilingRow == 13)
  894.    {
  895.       startDie();
  896.       return true;
  897.    }
  898.    var i = 0;
  899.    while(i < gBubbleRow.length)
  900.    {
  901.       if(0 >= gBubbleRow[i].length)
  902.       {
  903.          return false;
  904.       }
  905.       if(i + gCeilingRow >= 13)
  906.       {
  907.          startDie();
  908.          return true;
  909.       }
  910.       i++;
  911.    }
  912. }
  913. function startDie()
  914. {
  915.    gMode = cDIE;
  916.    gDieTimer = getTimer();
  917. }
  918. function checkCeiling(vTime)
  919. {
  920.    if(gCeilingTimer + gCeilingDelay < vTime)
  921.    {
  922.       gCeilingSound.attachSound("ceiling_sound");
  923.       gCeilingSound.start();
  924.       gMode = cCEILING;
  925.       gCeilingRow++;
  926.       gCeilingY = gCeilingRow * gRdY;
  927.       gCeilingTimer = vTime;
  928.    }
  929. }
  930. function popDone(vBubbleGraphic)
  931. {
  932.    var lBubble = vBubbleGraphic._parent._parent;
  933.    if(lBubble._parent == _root.level_bubble)
  934.    {
  935.       return undefined;
  936.    }
  937.    lBubble.removeMovieClip();
  938.    gPopping--;
  939. }
  940. function normalizeDirChange(vChange)
  941. {
  942.    if(Math.abs(vChange) == 3)
  943.    {
  944.       return 0;
  945.    }
  946.    if(vChange < -2)
  947.    {
  948.       return vChange + 6;
  949.    }
  950.    if(2 < vChange)
  951.    {
  952.       return vChange - 6;
  953.    }
  954.    return vChange;
  955. }
  956. function gridToDir(dr, dc)
  957. {
  958.    var lDir = -1;
  959.    if(dr == -1)
  960.    {
  961.       if(dc == -1)
  962.       {
  963.          lDir = 4;
  964.       }
  965.       else if(dc == 0)
  966.       {
  967.          lDir = 5;
  968.       }
  969.    }
  970.    else if(dr == 0)
  971.    {
  972.       if(dc == -1)
  973.       {
  974.          lDir = 3;
  975.       }
  976.       else if(dc == 1)
  977.       {
  978.          lDir = 0;
  979.       }
  980.    }
  981.    else if(dr == 1)
  982.    {
  983.       if(dc == 0)
  984.       {
  985.          lDir = 2;
  986.       }
  987.       else if(dc == 1)
  988.       {
  989.          lDir = 1;
  990.       }
  991.    }
  992.    return lDir;
  993. }
  994. function turnDir(vDir, vChange)
  995. {
  996.    var lNewDir = vDir + vChange;
  997.    if(5 < lNewDir)
  998.    {
  999.       lNewDir -= 6;
  1000.    }
  1001.    else if(lNewDir < 0)
  1002.    {
  1003.       lNewDir += 6;
  1004.    }
  1005.    return lNewDir;
  1006. }
  1007. function sortByPositionDist(vPos1, vPos2)
  1008. {
  1009.    var lGridPos1 = getNeighborPos(gTarget,vPos1);
  1010.    var lLoc1 = gridToPixels(lGridPos1.r,lGridPos1.c);
  1011.    var lDist1 = pointDist(lLoc1,gTangentPosition);
  1012.    var lGridPos2 = getNeighborPos(gTarget,vPos2);
  1013.    var lLoc2 = gridToPixels(lGridPos2.r,lGridPos2.c);
  1014.    var lDist2 = pointDist(lLoc2,gTangentPosition);
  1015.    if(lDist2 < lDist1)
  1016.    {
  1017.       return 1;
  1018.    }
  1019.    if(lDist1 < lDist2)
  1020.    {
  1021.       return -1;
  1022.    }
  1023.    return 0;
  1024. }
  1025. function pointDist(p1, p2)
  1026. {
  1027.    var dx = p1.x - p2.x;
  1028.    var dy = p1.y - p2.y;
  1029.    return Math.sqrt(dx * dx + dy * dy);
  1030. }
  1031. function dirToGrid(vIndex)
  1032. {
  1033.    if(vIndex == 0 || vIndex == 1)
  1034.    {
  1035.       dc0 = 1;
  1036.    }
  1037.    else if(vIndex == 3 || vIndex == 4)
  1038.    {
  1039.       dc0 = -1;
  1040.    }
  1041.    else
  1042.    {
  1043.       dc0 = 0;
  1044.    }
  1045.    if(vIndex == 1 || vIndex == 2)
  1046.    {
  1047.       dr0 = 1;
  1048.    }
  1049.    else if(vIndex == 4 || vIndex == 5)
  1050.    {
  1051.       dr0 = -1;
  1052.    }
  1053.    else
  1054.    {
  1055.       dr0 = 0;
  1056.    }
  1057.    return {dr:dr0,dc:dc0};
  1058. }
  1059. function getNeighborPos(vObj, vIndex)
  1060. {
  1061.    var r0 = vObj.pRow;
  1062.    var c0 = vObj.pCol;
  1063.    if(vIndex == 0 || vIndex == 1)
  1064.    {
  1065.       c0 += 1;
  1066.    }
  1067.    else if(vIndex == 3 || vIndex == 4)
  1068.    {
  1069.       c0 -= 1;
  1070.    }
  1071.    if(vIndex == 1 || vIndex == 2)
  1072.    {
  1073.       r0 += 1;
  1074.    }
  1075.    else if(vIndex == 4 || vIndex == 5)
  1076.    {
  1077.       r0 -= 1;
  1078.    }
  1079.    return {r:r0,c:c0};
  1080. }
  1081. function getBubbleAt(r, c)
  1082. {
  1083.    if(r < 0 || c < 0)
  1084.    {
  1085.       return -1;
  1086.    }
  1087.    if(Math.ceil(r / 2) + gRowLength - 1 < c)
  1088.    {
  1089.       return -1;
  1090.    }
  1091.    if(c < Math.ceil(r / 2))
  1092.    {
  1093.       return -1;
  1094.    }
  1095.    var b = gBubble[r][c];
  1096.    if(b == undefined)
  1097.    {
  1098.       return 0;
  1099.    }
  1100.    return b;
  1101. }
  1102. function getOne(array, x)
  1103. {
  1104.    var i = 0;
  1105.    while(i < array.length)
  1106.    {
  1107.       if(x == array[i])
  1108.       {
  1109.          return i;
  1110.       }
  1111.       i++;
  1112.    }
  1113.    return -1;
  1114. }
  1115. function reflect(vAngle1, vAngle2)
  1116. {
  1117.    var lRemapAngle1 = remapAngle(vAngle1,vAngle2);
  1118.    if(1.5707963267948966 < Math.abs(lRemapAngle1))
  1119.    {
  1120.       vAngle2 += 3.141592653589793;
  1121.       vAngle2 = normalizeAngle(vAngle2);
  1122.    }
  1123.    var lDiff = remapAngle(vAngle1,vAngle2);
  1124.    vAngle1 -= 2 * lDiff;
  1125.    vAngle1 = normalizeAngle(vAngle1);
  1126.    return vAngle1;
  1127. }
  1128. function updateScore(vChange)
  1129. {
  1130.    score += vChange;
  1131.    scorecheck = String(Number(scorecheck) + vChange);
  1132.    _root.score_display = scorecheck;
  1133. }
  1134. function levelOver()
  1135. {
  1136.    gLevel++;
  1137.    if(gLevel >= gNumLevels)
  1138.    {
  1139.       gRandomLevels.val = true;
  1140.    }
  1141.    gotoAndStop(3);
  1142. }
  1143. function playAgain()
  1144. {
  1145.    _root.gotoAndStop("intro");
  1146. }
  1147. function submitScore()
  1148. {
  1149.    extra += "Level " + gLevel;
  1150.    stats += "";
  1151.    loadMovie("game.swf?score=" + score + "&scorecheck=" + scorecheck + "&extra=" + extra + "&stats=" + stats + "&scoremode=" + scoremode + "&gamename=" + gamename + "&textname=" + textname,_root);
  1152. }
  1153. function dist(x0, y0, x1, y1)
  1154. {
  1155.    var dx = x0 - x1;
  1156.    var dy = y0 - y1;
  1157.    return Math.sqrt(dx * dx + dy * dy);
  1158. }
  1159. function pixelsToPos(vHubX, vHubY, vLocX, vLocY)
  1160. {
  1161.    var dx = vLocX - vHubX;
  1162.    var dy = vLocY - vHubY;
  1163.    var a = Math.atan2(dy,dx);
  1164.    if(a < 0)
  1165.    {
  1166.       var lPos = 3 + (a + 3.141592653589793) * 3 / 3.141592653589793;
  1167.    }
  1168.    else
  1169.    {
  1170.       var lPos = a * 3 / 3.141592653589793;
  1171.    }
  1172.    return lPos;
  1173. }
  1174. stop();
  1175.